package cn.innosmart.aq.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by David on 2015/12/1.
 */
public class WorkLog {
    //属性值列表
    private JSONArray properties;
    private String ps;
    private String location;
    private long time;

    public WorkLog(JSONObject jsonObject) {
        JSONObject content = null;
        try {
            content = new JSONObject(jsonObject.getString("content"));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        try {
            this.properties = content.getJSONArray("property");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        try {
            this.time = jsonObject.getLong("time");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        try {
            this.ps = content.getString("ps");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        try {
            this.location = content.getString("location");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public JSONArray getProperties() {
        return properties;
    }

    public void setProperties(JSONArray properties) {
        this.properties = properties;
    }

    public String getPs() {
        return ps;
    }

    public void setPs(String ps) {
        this.ps = ps;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public JSONObject toJsonObject() {
        JSONObject jsonRoot = new JSONObject();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("property", properties);
            jsonObject.put("ps", ps);
            jsonObject.put("location", location);
            jsonRoot.put("content", jsonObject);
            jsonRoot.put("time", time);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonRoot;
    }
}

